package com.ele.Service.impl;


import com.ele.Dao.BusinessDao;
import com.ele.Dao.DaoImpl.BusinessDaoImp;
import com.ele.Pojo.Business;
import com.ele.Pojo.PageResult;
import com.ele.Pojo.PageResult;
import com.ele.Service.BusinessService;


import java.sql.SQLException;
import java.util.List;

public class BusinessServiceImpl implements BusinessService {

    //创建dao对象
    BusinessDaoImp businessDaoImp = new BusinessDaoImp();

    /**
     * 加载全部
     * @return
     */
    @Override
    public List<Business> getAllBusiness(){
        try {
            return businessDaoImp.getAllBusiness();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 注册
     * @param account
     * @param password
     * @param telephone
     * @param contact
     * @return
     */
    @Override
    public Integer businessRegist(String account, String password, String telephone, String contact) {
        try {
            return businessDaoImp.businessRegister(account,password,telephone,contact);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 登录
     * @param account
     * @param password
     * @return
     */
    @Override
    public Business businessLogin(String account, String password) {
        try {
            return businessDaoImp.businessLogin(account,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 修改
     * @param account
     * @param password
     * @param telephone
     * @param contact
     * @return
     */
    @Override
    public Integer UpdateBusiness(String account, String password, String telephone, String contact ,String id) {
        try {
            return businessDaoImp.UpdateBusiness(account,password,telephone,contact,id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer deleteBusiness(String id) {
        try {
            return businessDaoImp.deleteBusiness(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
    //查找
    @Override
    public List<Business> queryBusiness(String account, String telephone, String contact) {
        try {
            return businessDaoImp.queryBusiness(account,telephone,contact);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public PageResult<List<Business>> findAll(String account , String contact, String telephone, String currentPage, String pageSize ) {
        try{
            // 分页和条件查询数据
            List<Business> list =  this.businessDaoImp.findAll(account,contact,telephone,currentPage,pageSize);
            // 需要查询数据库的总记录数
            Long total = this.businessDaoImp.selectCount();
            // 手动创建一个用于封装分页结果集的对象
            PageResult<List<Business>> pageResult = new PageResult<List<Business>>();
            // 手动给分页结果集的对象上设置参数 ， 分页查询出来当前页面需要显示的数据
            pageResult.setDatas(list);
            // 手动给分页结果集的对象上设置参数 ， 数据表的总记录数
            pageResult.setTotal(total);
            return pageResult;
        }catch (SQLException e){
            e.printStackTrace();
        }
        return null;
    }


}
